package com.voxel.sense.infomsg.utils;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.voxel.sense.infomsg.R;
import com.youth.banner.loader.ImageLoader;

import cyy.example.com.facotry.constants.CommonConstants;
import cyy.example.com.facotry.model.api.response.BannerEntity;


/**
 * 轮播图图片加载类
 */
public class GlideImageLoader extends ImageLoader {
    @Override
    public void displayImage(Context context, Object data, ImageView imageView) {
        //具体方法内容自己去选择，次方法是为了减少banner过多的依赖第三方包，所以将这个权限开放给使用者去选择
        if (data instanceof BannerEntity) {
            BannerEntity entity = (BannerEntity) data;
            String picturePath = entity.getPicturePath();
            loadPick(context, CommonConstants.FILE_CONFIG_URL + picturePath, imageView);
        } else if (data instanceof String) {
            loadPick(context, (String) data, imageView);
        } else {
            Glide.with(context.getApplicationContext())
                    .load(R.mipmap.banner)
                    .apply(RequestOptions.centerCropTransform() // 居中剪切
                            .placeholder(R.mipmap.icon_img_loading))
                    .into(imageView);
        }
    }

    private void loadPick(Context context, String path, ImageView imageView) {
        Glide.with(context.getApplicationContext())
                .load(path)
                .apply(RequestOptions.centerCropTransform() // 居中剪切
                        .placeholder(R.mipmap.icon_img_loading)
                        .error(R.mipmap.banner))
                .into(imageView);

    }
}
